package br.com.news.web.service;

import java.util.ArrayList;
import java.util.List;

import br.com.news.utils.database.beans.EnqueteBean;
import br.com.news.utils.database.beans.RespostaEnqueteBean;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;

public class RespostaEnqueteService {

	public List<EnqueteBean> lastPoll() {
	    Client c = Client.create();
	    WebResource wr = c.resource("http://localhost:8080/news-web-service-rest/enquetes/last/poll");
	    String json = wr.get(String.class);
	    Gson gson = new Gson();
	    List<EnqueteBean> enquetes = gson.fromJson(json, new TypeToken<ArrayList<EnqueteBean>>(){}.getType());
	    
		return enquetes;
	}
	
	public List<RespostaEnqueteBean> resultVote(EnqueteBean enquete) {
		Long idEnquete = enquete.getIdEnquete();		
		Client c = Client.create();
	    WebResource wr = c.resource("http://localhost:8080/news-web-service-rest/resposta/result/vote/"+idEnquete);
	    String json = wr.get(String.class);
	    Gson gson = new Gson();
	    List<RespostaEnqueteBean> resposta = gson.fromJson(json, new TypeToken<ArrayList<RespostaEnqueteBean>>(){}.getType());
	    
		return resposta;	
	}

}
